<?php

namespace App\Http\Controllers\staff;

use Illuminate\Http\Request;
use DB;
use Cookie;
use Hash;
use App\Http\Controllers\Controller;
//模型
use App\Models\Role;

class OverviewController extends Controller
{
    public function getIndex(Request $request){
        //获取工单信息
        $staffInfo = $request -> cookie('staffInfo');
        $areaArr = DB::table('area_staff as as')
            -> leftJoin('area as a','a.id','=','as.area_id')
            -> select('area_id')
            -> where('staff_id',$staffInfo['id'])
            -> get();
        //查询管理范围内合同信息
        $finish = DB::table('room as r')
            -> leftJoin('area as a','a.id','=','r.area_id')
            -> leftJoin('contract as c','c.room_id','=','r.id')
            -> select('c.*','r.name as rname','a.name as aname')
            -> whereIn('r.area_id',$areaArr)
            -> where('c.status',1)
            -> get();
        $unfinish = DB::table('room as r')
            -> leftJoin('area as a','a.id','=','r.area_id')
            -> leftJoin('contract as c','c.room_id','=','r.id')
            -> select('c.*','r.name as rname','a.name as aname')
            -> whereIn('r.area_id',$areaArr)
            -> where('c.status',0)
            -> get();
        $data = array_merge($unfinish,$finish);
        $ucount = count($unfinish);
        $fcount = count($finish);
        $all = $ucount + $fcount;
        return view('staff.overview.index',['data'=>$data,'ucount'=>$ucount,'fcount'=>$fcount,'all'=>$all]);
    }
}